app.controller("rankingCtrl",function($scope,$http){
    //选项卡选中
    $scope.readTime = true;
    $scope.integralSearch = false;
    $scope.gradeSearch = false;
    //列表显示
    $scope.readTimeDiv = true;
    $scope.integralSearchDiv = false;
    $scope.gradeSearchDiv = false;
    var u = JSON.parse(localStorage.getItem("UserInfo"));
    // var getPath = JSON.parse(localStorage.getItem("getPath"));
    $scope.changeList = function (type) {
        if(type==1){
            $scope.readTime = true;
            $scope.integralSearch = false;
            $scope.gradeSearch = false;

            $scope.readTimeDiv = true;
            $scope.integralSearchDiv = false;
            $scope.gradeSearchDiv = false;
            $scope.findTopAndMyRank();
        }else if(type==2){
            $scope.readTime = false;
            $scope.integralSearch = true;
            $scope.gradeSearch = false;

            $scope.readTimeDiv = false;
            $scope.integralSearchDiv = true;
            $scope.gradeSearchDiv = false;
            $scope.findTopAndMyRankByScore();
        }else if(type==3){
            $scope.readTime = false;
            $scope.integralSearch = false;
            $scope.gradeSearch = true;

            $scope.readTimeDiv = false;
            $scope.integralSearchDiv = false;
            $scope.gradeSearchDiv = true;
            $scope.findTopAndMyRankByExam();
        }
    }
    //序号样式
    $scope.setColor = function (list) {
        
    }
    angular.element(document).ready(function(){
        $scope.nowTime = new Date().Format("yyyy-MM-dd");
        $scope.findTopAndMyRank();
    });
    //查询阅读时间
    $scope.findTopAndMyRank = function () {
        var url = getPath.url+getPath.name+"/app/findTopAndMyRank";
        var param = {
            userId:u.userId
        }
        $http({
            url: url,
            method: "POST",
            headers:{'Content-Type':'application/x-www-form-urlencoded'},
            data: param
        }).success(function (data) {
                if (data.resultCode == 200) {
                    var res = data.resultBean;
                    //我的排名
                    $scope.myReadRank = res.myRank;
                    var list = res.baseTimeList;
                    for(var i=0;i<list.length;i++){
                        if((i+1)==1){
                            list[i].class = "first";
                        }else if((i+1)==2){
                            list[i].class = "two";
                        }else if((i+1)==3){
                            list[i].class = "three";
                        }else{
                            list[i].class = "";
                        }
                    }
                    $scope.rankList = list;
                } else {
                    $ionicLoading.show({
                        template: data.result,
                        duration: 3000
                    });
                }
            })
            .error(function () {
                $ionicLoading.hide();
                $ionicLoading.show({
                    template: "获取阅读章节失败",
                    duration: 3000
                });
            });
    }
    //查询积分排名
    $scope.findTopAndMyRankByScore = function () {
        var url = getPath.url+getPath.name+"/app/findTopAndMyRankByScore";
        var param = {
            userId:u.userId
        }
        $http({
            url: url,
            method: "POST",
            headers:{'Content-Type':'application/x-www-form-urlencoded'},
            data: param
        }).success(function (data) {
                if (data.resultCode == 200) {
                    var res = data.resultBean;
                    //我的排名
                    $scope.myScoreRank = res.myRank;
                    var list = res.scoreDetailList;
                    for(var i=0;i<list.length;i++){
                        if((i+1)==1){
                            list[i].class = "first";
                        }else if((i+1)==2){
                            list[i].class = "two";
                        }else if((i+1)==3){
                            list[i].class = "three";
                        }else{
                            list[i].class = "";
                        }
                    }
                    $scope.scoreList = list;
                } else {
                    $ionicLoading.show({
                        template: data.result,
                        duration: 3000
                    });
                }
            })
            .error(function () {
                $ionicLoading.hide();
                $ionicLoading.show({
                    template: "获取阅读章节失败",
                    duration: 3000
                });
            });
    }
    //查询成绩排名
    $scope.findTopAndMyRankByExam = function () {
        var url = getPath.url+getPath.name+"/app/findTopAndMyRankByExam";
        var param = {
            userId:u.userId
        }
        $http({
            url: url,
            method: "POST",
            headers:{'Content-Type':'application/x-www-form-urlencoded'},
            data: param
        }).success(function (data) {
                if (data.resultCode == 200) {
                    var res = data.resultBean;
                    //我的排名
                    $scope.myGradeRank = res.myRank;
                    var list = res.examScoreList;
                    for(var i=0;i<list.length;i++){
                        if((i+1)==1){
                            list[i].class = "first";
                        }else if((i+1)==2){
                            list[i].class = "two";
                        }else if((i+1)==3){
                            list[i].class = "three";
                        }else{
                            list[i].class = "";
                        }
                    }
                    $scope.examList = list;
                } else {
                    $ionicLoading.show({
                        template: data.result,
                        duration: 3000
                    });
                }
            })
            .error(function () {
                $ionicLoading.hide();
                $ionicLoading.show({
                    template: "获取阅读章节失败",
                    duration: 3000
                });
            });
    }
});